Improve fuzzer code coverage (#239)
authorRandy <randy408@protonmail.com>
Thu, 26 May 2022 12:58:54 +0000 (14:58 +0200)
committerGitHub <noreply@github.com>
Thu, 26 May 2022 12:58:54 +0000 (08:58 -0400)
* fuzz: test grapheme break functions

* fuzz: cover character lumping

test/fuzzer.c

index 15007c9de773692667b3468c5caa76a8a11d3991..b5349a322c9f01c487389607688a7f704373bd12 100644 (file)
@@ -11,7 +11,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
     if(data[size-1] != '\0') return 0;
 
     const uint8_t* ptr = data;
-    utf8proc_int32_t c = 0;
+    utf8proc_int32_t c = 0, c_prev = 0, state = 0;
     utf8proc_option_t options;
     utf8proc_ssize_t ret, bytes = 0;
     size_t len = strlen((const char*)data);
@@ -34,6 +34,11 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
         utf8proc_category(c);
         utf8proc_category_string(c);
         utf8proc_codepoint_valid(c);
+        
+        utf8proc_grapheme_break(c_prev, c);
+        utf8proc_grapheme_break_stateful(c_prev, c, &state);
+        
+        c_prev = c;
     }
     
     utf8proc_int32_t *copy = size >= 4 ? NULL : malloc(size);
@@ -58,6 +63,10 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
         memcpy(copy, data, size);
         utf8proc_normalize_utf32(copy, size, options);
 
+        options = UTF8PROC_LUMP;
+        memcpy(copy, data, size);
+        utf8proc_normalize_utf32(copy, size, options);
+
         options = 0;
         memcpy(copy, data, size);
         utf8proc_normalize_utf32(copy, size, options);